﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[spObtenListaEstudios](
	@pnIdLaboratorio INT,
	@psExcluirEstudios VARCHAR(MAX)
)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
	DECLARE @tblEstudios TABLE(IdEstudio INT)
	
	IF ISNULL(@psExcluirEstudios,'') <> ''
	BEGIN
		INSERT INTO @tblEstudios
	        ( IdEstudio )
		SELECT Item FROM dbo.fnConvertToTable(@psExcluirEstudios, ',')
	END
		
	SELECT	d.IdEstudio, d.NombreEstudio
	FROM	dbo.CatEstudio (NOLOCK) d
	WHERE	d.IdLaboratorio = @pnIdLaboratorio
	AND		d.IdEstudio	NOT IN(SELECT IdEstudio FROM @tblEstudios)
	ORDER BY NombreEstudio;
	
	SET NOCOUNT OFF;
END